package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.S_ACTIVITY_MULTIPLE_GET_REWARD, desc = "")
public class MultipleGetActivityRewardCmd extends AbstractCommand {

	private int activityId;

	private List<Integer> conditionIdList;

	private ActivityRewardResult rewardResult;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		ActivityProto.ActivityMultipleGetRewardReqMsg reqMsg = ActivityProto.ActivityMultipleGetRewardReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		conditionIdList = reqMsg.getConditionIdList();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
		if(null == activityInfo){
			rewardResult = new ActivityRewardResult();
			rewardResult.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
			return;
		}
		// 目前只有统兵
		if (activityInfo.getType() == eActivityType.TongBingActivity.getValue()){
			rewardResult = player.getModule(ActivityModule.class).getMultipleActivityReward(activityId,conditionIdList);
		}else if (activityInfo.getType() == eActivityType.TonBingActivity.getValue()){
			rewardResult = player.getModule(ActivityModule.class).getMultipleActivityReward(activityId,conditionIdList);
		}else{
			rewardResult = new ActivityRewardResult();
			rewardResult.setRet(GameErrorCode.E_ACTIVITY_MULTIPLE_GET_REWARD_TYPE_NO_SUPPORT);
			return;
		}

	}

	@Override
	public void sendData(GamePlayer player) {
		ActivityProto.ActivityMultipleGetRewardRespMsg.Builder respMsg = ActivityProto.ActivityMultipleGetRewardRespMsg.newBuilder();
		respMsg.setActivityId(activityId);
		respMsg.setRet(rewardResult.getRet());
		respMsg.setReward(rewardResult.getReward());
		respMsg.addAllConditionId(rewardResult.getConditionIdList());
		player.sendPacket(Protocol.U_ACTIVITY_MULTIPLE_GET_REWARD, respMsg);
	}

}
